import { unref } from 'vue'
import { nanoid } from 'nanoid'

export const useFileUpload = (options = {}) => {
    const { fileNameList = [], formData = {}} = options

    const uploadDelete = []

    // 文件上传，用于给AttachmentList组件的onAdd事件
    const uploadFile = (item, fileList) => {
        uploadDelete.addItem(item)
    }
    // 文件删除，用于给AttachmentList组件的onDelete事件
    const deleteFile = item => {
        uploadDelete.deleteItem(item)
    }
    // 表单提交
    const confirmFile = () => {
        uploadDelete.handleConfirm()
    }
    // 表单取消提交
    const cancelFile = () => {
        uploadDelete.handleCancel()
    }

    return {
        uploadFile,
        deleteFile,
        confirmFile,
        cancelFile,
        initFileListData

    }
}